

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>PHP S3 实例 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="Python S3 Examples" href="../python/" />
    <link rel="prev" title="Perl S3 Examples" href="../perl/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../">Ceph 对象网关</a> &raquo;</li>
        
          <li><a href="../">Ceph 对象网关的 S3 API</a> &raquo;</li>
        
      <li>PHP S3 实例</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../../_sources/radosgw/s3/php.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../">
          

          
            
            <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../">Ceph 对象网关</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../frontends/">HTTP 前端</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../placement/">存储池归置与存储类</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../multisite/">多站配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../multisite-sync-policy/">多站同步策略配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pools/">存储池的配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../config-ref/">配置参考</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../admin/">管理指南</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../">S3 API</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="../#api">API</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="../commons/">常见的</a></li>
<li class="toctree-l4"><a class="reference internal" href="../authentication/">认证</a></li>
<li class="toctree-l4"><a class="reference internal" href="../serviceops/">Service Ops</a></li>
<li class="toctree-l4"><a class="reference internal" href="../bucketops/">Bucket Ops</a></li>
<li class="toctree-l4"><a class="reference internal" href="../objectops/">Object Ops</a></li>
<li class="toctree-l4"><a class="reference internal" href="../cpp/">C++</a></li>
<li class="toctree-l4"><a class="reference internal" href="../csharp/">C#</a></li>
<li class="toctree-l4"><a class="reference internal" href="../java/">Java</a></li>
<li class="toctree-l4"><a class="reference internal" href="../perl/">Perl</a></li>
<li class="toctree-l4 current"><a class="current reference internal" href="#">PHP</a></li>
<li class="toctree-l4"><a class="reference internal" href="../python/">Python</a></li>
<li class="toctree-l4"><a class="reference internal" href="../ruby/">Ruby AWS::SDK Examples (aws-sdk gem ~&gt;2)</a></li>
<li class="toctree-l4"><a class="reference internal" href="../ruby/#ruby-aws-s3-examples-aws-s3-gem">Ruby AWS::S3 Examples (aws-s3 gem)</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../#id1">功能支持情况</a></li>
<li class="toctree-l3"><a class="reference internal" href="../#header">不支持的 Header 字段</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../rgw-cache/">Data caching and CDN</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../swift/">Swift API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../adminops/">管理操作 API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/">Python 接口</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../nfs/">通过 NFS 导出</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../keystone/">与 OpenStack Keystone 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../barbican/">与 OpenStack Barbican 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../vault/">与 HashiCorp Vault 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../kmip/">KMIP Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../opa/">与 Open Policy Agent 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../multitenancy/">多租户</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../compression/">压缩</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ldap-auth/">LDAP 认证</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../encryption/">服务器端加密</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../bucketpolicy/">桶策略</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../dynamicresharding/">动态的桶索引重分片</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../mfa/">多因子认证</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../sync-modules/">同步模块</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../notifications/">Bucket Notifications</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../layout/">RADOS 中的数据布局</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../STS/">STS</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../STSLite/">STS Lite</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../keycloak/">Keycloak</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../role/">Role</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../session-tags/">Session Tags</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../orphans/">Orphan List and Associated Tooliing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../oidc/">OpenID Connect Provider</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../troubleshooting/">故障排除</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../man/8/radosgw/">radosgw 手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../man/8/radosgw-admin/">radosgw-admin 手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../qat-accel/">使用 QAT 为加密和压缩提速</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../s3select/">S3-select</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../lua-scripting/">Lua Scripting</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../d3n_datacache/">D3N Data Cache</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-transition/">Cloud Transition</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="php-s3">
<span id="php"></span><h1>PHP S3 实例<a class="headerlink" href="#php-s3" title="Permalink to this headline">¶</a></h1>
<div class="section" id="installing-aws-php-sdk">
<h2>Installing AWS PHP SDK<a class="headerlink" href="#installing-aws-php-sdk" title="Permalink to this headline">¶</a></h2>
<p>This installs AWS PHP SDK using composer (see <a class="reference external" href="https://getcomposer.org/download/">here</a> how to install composer).</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ composer install aws/aws-sdk-php
</pre></div>
</div>
</div>
<div class="section" id="creating-a-connection">
<h2>Creating a Connection<a class="headerlink" href="#creating-a-connection" title="Permalink to this headline">¶</a></h2>
<p>This creates a connection so that you can interact with the server.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The client initialization requires a region so we use <code class="docutils literal notranslate"><span class="pre">''</span></code>.</p>
</div>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Aws\S3\S3Client</span><span class="p">;</span>

<span class="nb">define</span><span class="p">(</span><span class="s1">&#39;AWS_KEY&#39;</span><span class="p">,</span> <span class="s1">&#39;place access key here&#39;</span><span class="p">);</span>
<span class="nb">define</span><span class="p">(</span><span class="s1">&#39;AWS_SECRET_KEY&#39;</span><span class="p">,</span> <span class="s1">&#39;place secret key here&#39;</span><span class="p">);</span>
<span class="nv">$ENDPOINT</span> <span class="o">=</span> <span class="s1">&#39;http://objects.dreamhost.com&#39;</span><span class="p">;</span>

<span class="c1">// require the amazon sdk from your composer vendor dir</span>
<span class="k">require</span> <span class="no">__DIR__</span><span class="o">.</span><span class="s1">&#39;/vendor/autoload.php&#39;</span><span class="p">;</span>

<span class="c1">// Instantiate the S3 class and point it at the desired host</span>
<span class="nv">$client</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">S3Client</span><span class="p">([</span>
    <span class="s1">&#39;region&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
    <span class="s1">&#39;version&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;2006-03-01&#39;</span><span class="p">,</span>
    <span class="s1">&#39;endpoint&#39;</span> <span class="o">=&gt;</span> <span class="nv">$ENDPOINT</span><span class="p">,</span>
    <span class="s1">&#39;credentials&#39;</span> <span class="o">=&gt;</span> <span class="p">[</span>
        <span class="s1">&#39;key&#39;</span> <span class="o">=&gt;</span> <span class="nx">AWS_KEY</span><span class="p">,</span>
        <span class="s1">&#39;secret&#39;</span> <span class="o">=&gt;</span> <span class="nx">AWS_SECRET_KEY</span>
    <span class="p">],</span>
    <span class="c1">// Set the S3 class to use objects.dreamhost.com/bucket</span>
    <span class="c1">// instead of bucket.objects.dreamhost.com</span>
    <span class="s1">&#39;use_path_style_endpoint&#39;</span> <span class="o">=&gt;</span> <span class="k">true</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<div class="section" id="listing-owned-buckets">
<h2>Listing Owned Buckets<a class="headerlink" href="#listing-owned-buckets" title="Permalink to this headline">¶</a></h2>
<p>This gets a <code class="docutils literal notranslate"><span class="pre">AWS\Result</span></code> instance that is more convenient to visit using array access way.
This also prints out the bucket name and creation date of each bucket.</p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$listResponse</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">listBuckets</span><span class="p">();</span>
<span class="nv">$buckets</span> <span class="o">=</span> <span class="nv">$listResponse</span><span class="p">[</span><span class="s1">&#39;Buckets&#39;</span><span class="p">];</span>
<span class="k">foreach</span> <span class="p">(</span><span class="nv">$buckets</span> <span class="k">as</span> <span class="nv">$bucket</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">echo</span> <span class="nv">$bucket</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">]</span> <span class="o">.</span> <span class="s2">&quot;</span><span class="se">\t</span><span class="s2">&quot;</span> <span class="o">.</span> <span class="nv">$bucket</span><span class="p">[</span><span class="s1">&#39;CreationDate&#39;</span><span class="p">]</span> <span class="o">.</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The output will look something like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mahbuckat1</span>   <span class="mi">2011</span><span class="o">-</span><span class="mi">04</span><span class="o">-</span><span class="mi">21</span><span class="n">T18</span><span class="p">:</span><span class="mi">05</span><span class="p">:</span><span class="mf">39.000</span><span class="n">Z</span>
<span class="n">mahbuckat2</span>   <span class="mi">2011</span><span class="o">-</span><span class="mi">04</span><span class="o">-</span><span class="mi">21</span><span class="n">T18</span><span class="p">:</span><span class="mi">05</span><span class="p">:</span><span class="mf">48.000</span><span class="n">Z</span>
<span class="n">mahbuckat3</span>   <span class="mi">2011</span><span class="o">-</span><span class="mi">04</span><span class="o">-</span><span class="mi">21</span><span class="n">T18</span><span class="p">:</span><span class="mi">07</span><span class="p">:</span><span class="mf">18.000</span><span class="n">Z</span>
</pre></div>
</div>
</div>
<div class="section" id="creating-a-bucket">
<h2>Creating a Bucket<a class="headerlink" href="#creating-a-bucket" title="Permalink to this headline">¶</a></h2>
<p>This creates a new bucket called <code class="docutils literal notranslate"><span class="pre">my-new-bucket</span></code> and returns a
<code class="docutils literal notranslate"><span class="pre">AWS\Result</span></code> object.</p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$client</span><span class="o">-&gt;</span><span class="na">createBucket</span><span class="p">([</span><span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-new-bucket&#39;</span><span class="p">]);</span>
</pre></div>
</div>
</div>
<div class="section" id="list-a-bucket-s-content">
<h2>List a Bucket’s Content<a class="headerlink" href="#list-a-bucket-s-content" title="Permalink to this headline">¶</a></h2>
<p>This gets a <code class="docutils literal notranslate"><span class="pre">AWS\Result</span></code> instance that is more convenient to visit using array access way.
This then prints out each object’s name, the file size, and last modified date.</p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$objectsListResponse</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">listObjects</span><span class="p">([</span><span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="nv">$bucketname</span><span class="p">]);</span>
<span class="nv">$objects</span> <span class="o">=</span> <span class="nv">$objectsListResponse</span><span class="p">[</span><span class="s1">&#39;Contents&#39;</span><span class="p">]</span> <span class="o">??</span> <span class="p">[];</span>
<span class="k">foreach</span> <span class="p">(</span><span class="nv">$objects</span> <span class="k">as</span> <span class="nv">$object</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">echo</span> <span class="nv">$object</span><span class="p">[</span><span class="s1">&#39;Key&#39;</span><span class="p">]</span> <span class="o">.</span> <span class="s2">&quot;</span><span class="se">\t</span><span class="s2">&quot;</span> <span class="o">.</span> <span class="nv">$object</span><span class="p">[</span><span class="s1">&#39;Size&#39;</span><span class="p">]</span> <span class="o">.</span> <span class="s2">&quot;</span><span class="se">\t</span><span class="s2">&quot;</span> <span class="o">.</span> <span class="nv">$object</span><span class="p">[</span><span class="s1">&#39;LastModified&#39;</span><span class="p">]</span> <span class="o">.</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If there are more than 1000 objects in this bucket,
you need to check $objectsListResponse[‘isTruncated’]
and run again with the name of the last key listed.
Keep doing this until isTruncated is not true.</p>
</div>
<p>The output will look something like this if the bucket has some files:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">myphoto1</span><span class="o">.</span><span class="n">jpg</span> <span class="mi">251262</span>  <span class="mi">2011</span><span class="o">-</span><span class="mi">08</span><span class="o">-</span><span class="mi">08</span><span class="n">T21</span><span class="p">:</span><span class="mi">35</span><span class="p">:</span><span class="mf">48.000</span><span class="n">Z</span>
<span class="n">myphoto2</span><span class="o">.</span><span class="n">jpg</span> <span class="mi">262518</span>  <span class="mi">2011</span><span class="o">-</span><span class="mi">08</span><span class="o">-</span><span class="mi">08</span><span class="n">T21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mf">01.000</span><span class="n">Z</span>
</pre></div>
</div>
</div>
<div class="section" id="deleting-a-bucket">
<h2>Deleting a Bucket<a class="headerlink" href="#deleting-a-bucket" title="Permalink to this headline">¶</a></h2>
<p>This deletes the bucket called <code class="docutils literal notranslate"><span class="pre">my-old-bucket</span></code> and returns a
<code class="docutils literal notranslate"><span class="pre">AWS\Result</span></code> object</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The Bucket must be empty! Otherwise it won’t work!</p>
</div>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$client</span><span class="o">-&gt;</span><span class="na">deleteBucket</span><span class="p">([</span><span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-old-bucket&#39;</span><span class="p">]);</span>
</pre></div>
</div>
</div>
<div class="section" id="creating-an-object">
<h2>Creating an Object<a class="headerlink" href="#creating-an-object" title="Permalink to this headline">¶</a></h2>
<p>This creates an object <code class="docutils literal notranslate"><span class="pre">hello.txt</span></code> with the string <code class="docutils literal notranslate"><span class="pre">&quot;Hello</span> <span class="pre">World!&quot;</span></code></p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$client</span><span class="o">-&gt;</span><span class="na">putObject</span><span class="p">([</span>
    <span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-bucket-name&#39;</span><span class="p">,</span>
    <span class="s1">&#39;Key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;hello.txt&#39;</span><span class="p">,</span>
    <span class="s1">&#39;Body&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Hello World!&quot;</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<div class="section" id="change-an-object-s-acl">
<h2>Change an Object’s ACL<a class="headerlink" href="#change-an-object-s-acl" title="Permalink to this headline">¶</a></h2>
<p>This makes the object <code class="docutils literal notranslate"><span class="pre">hello.txt</span></code> to be publicly readable and
<code class="docutils literal notranslate"><span class="pre">secret_plans.txt</span></code> to be private.</p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$client</span><span class="o">-&gt;</span><span class="na">putObjectAcl</span><span class="p">([</span>
    <span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-bucket-name&#39;</span><span class="p">,</span>
    <span class="s1">&#39;Key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;hello.txt&#39;</span><span class="p">,</span>
    <span class="s1">&#39;ACL&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;public-read&#39;</span>
<span class="p">]);</span>
<span class="nv">$client</span><span class="o">-&gt;</span><span class="na">putObjectAcl</span><span class="p">([</span>
    <span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-bucket-name&#39;</span><span class="p">,</span>
    <span class="s1">&#39;Key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;secret_plans.txt&#39;</span><span class="p">,</span>
    <span class="s1">&#39;ACL&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;private&#39;</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<div class="section" id="delete-an-object">
<h2>Delete an Object<a class="headerlink" href="#delete-an-object" title="Permalink to this headline">¶</a></h2>
<p>This deletes the object <code class="docutils literal notranslate"><span class="pre">goodbye.txt</span></code></p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$client</span><span class="o">-&gt;</span><span class="na">deleteObject</span><span class="p">([</span><span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-bucket-name&#39;</span><span class="p">,</span> <span class="s1">&#39;Key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;goodbye.txt&#39;</span><span class="p">]);</span>
</pre></div>
</div>
</div>
<div class="section" id="download-an-object-to-a-file">
<h2>Download an Object (to a file)<a class="headerlink" href="#download-an-object-to-a-file" title="Permalink to this headline">¶</a></h2>
<p>This downloads the object <code class="docutils literal notranslate"><span class="pre">poetry.pdf</span></code> and saves it in
<code class="docutils literal notranslate"><span class="pre">/home/larry/documents/</span></code></p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$object</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">getObject</span><span class="p">([</span><span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-bucket-name&#39;</span><span class="p">,</span> <span class="s1">&#39;Key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;poetry.pdf&#39;</span><span class="p">]);</span>
<span class="nb">file_put_contents</span><span class="p">(</span><span class="s1">&#39;/home/larry/documents/poetry.pdf&#39;</span><span class="p">,</span> <span class="nv">$object</span><span class="p">[</span><span class="s1">&#39;Body&#39;</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">getContents</span><span class="p">());</span>
</pre></div>
</div>
</div>
<div class="section" id="generate-object-download-urls-signed-and-unsigned">
<h2>Generate Object Download URLs (signed and unsigned)<a class="headerlink" href="#generate-object-download-urls-signed-and-unsigned" title="Permalink to this headline">¶</a></h2>
<p>This generates an unsigned download URL for <code class="docutils literal notranslate"><span class="pre">hello.txt</span></code>.
This works because we made <code class="docutils literal notranslate"><span class="pre">hello.txt</span></code> public by setting
the ACL above. This then generates a signed download URL
for <code class="docutils literal notranslate"><span class="pre">secret_plans.txt</span></code> that will work for 1 hour.
Signed download URLs will work for the time period even
if the object is private (when the time period is up,
the URL will stop working).</p>
<div class="highlight-php notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?php</span>
<span class="nv">$hello_url</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">getObjectUrl</span><span class="p">(</span><span class="s1">&#39;my-bucket-name&#39;</span><span class="p">,</span> <span class="s1">&#39;hello.txt&#39;</span><span class="p">);</span>
<span class="k">echo</span> <span class="nv">$hello_url</span><span class="o">.</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>

<span class="nv">$secret_plans_cmd</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">getCommand</span><span class="p">(</span><span class="s1">&#39;GetObject&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;Bucket&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;my-bucket-name&#39;</span><span class="p">,</span> <span class="s1">&#39;Key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;secret_plans.txt&#39;</span><span class="p">]);</span>
<span class="nv">$request</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">createPresignedRequest</span><span class="p">(</span><span class="nv">$secret_plans_cmd</span><span class="p">,</span> <span class="s1">&#39;+1 hour&#39;</span><span class="p">);</span>
<span class="k">echo</span> <span class="nv">$request</span><span class="o">-&gt;</span><span class="na">getUri</span><span class="p">()</span><span class="o">.</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>
</pre></div>
</div>
<p>The output of this will look something like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>http://objects.dreamhost.com/my-bucket-name/hello.txt
http://objects.dreamhost.com/my-bucket-name/secret_plans.txt?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=sandboxAccessKey%2F20190116%2F%2Fs3%2Faws4_request&amp;X-Amz-Date=20190116T125520Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=3600&amp;X-Amz-Signature=61921f07c73d7695e47a2192cf55ae030f34c44c512b2160bb5a936b2b48d923
</pre></div>
</div>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../python/" class="btn btn-neutral float-right" title="Python S3 Examples" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../perl/" class="btn btn-neutral float-left" title="Perl S3 Examples" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>